package gui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import service.Service;

import model.DelBehandling;
import model.LagerPlads;

/**
 * 
 * @author Lars
 *
 */

public class LagerRedigerLagerplads extends JDialog {

	private final JPanel contentPanel = new JPanel();
	
	private JButton btnNsteBehandling;
	private JButton btnLuk;
	
	private ButtonActionsListener buttonActionListener = new ButtonActionsListener();
	
	private LagerPlads lp;
	private JButton btnPlukFraMellemvaren;
	
	public LagerRedigerLagerplads(LagerPlads lp) {
		setTitle("Vis lagerplads");
		setModal(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 330, 190);
		getContentPane().setLayout(null);
		
		this.lp = lp;
		
		JLabel lblID = new JLabel("ID:");
		lblID.setBounds(12, 12, 153, 15);
		getContentPane().add(lblID);
		
		JLabel lblAntalStk = new JLabel("Antal stk:");
		lblAntalStk.setBounds(12, 39, 153, 15);
		getContentPane().add(lblAntalStk);
		
		JLabel lblNuvrendeBehandling = new JLabel("Nuværende behandling:");
		lblNuvrendeBehandling.setBounds(12, 66, 180, 15);
		getContentPane().add(lblNuvrendeBehandling);
		
		JLabel lblIdtext = new JLabel(lp.getMellemvare().getId()+"");
		lblIdtext.setBounds(200, 12, 61, 15);
		getContentPane().add(lblIdtext);
		
		JLabel lblAntalstktext = new JLabel(lp.getMellemvare().getAntalStk()+"");
		lblAntalstktext.setBounds(200, 39, 61, 15);
		getContentPane().add(lblAntalstktext);
		
		JLabel lblCurrentbehandlingtext = new JLabel();
		lblCurrentbehandlingtext.setBounds(200, 66, 100, 15);
		getContentPane().add(lblCurrentbehandlingtext);
		
		btnNsteBehandling = new JButton("N\u00E6ste Behandling");
		btnNsteBehandling.setBounds(12, 93, 179, 25);
		btnNsteBehandling.addActionListener(buttonActionListener);
		getContentPane().add(btnNsteBehandling);
		
		btnLuk = new JButton("Luk");
		btnLuk.setBounds(203, 93, 107, 25);
		btnLuk.addActionListener(buttonActionListener);
		
		getContentPane().add(btnLuk);
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		
		lblCurrentbehandlingtext.setText(lp.getMellemvare().getTimeStamps().get(lp.getMellemvare().getTimeStamps().size()-1).getDelBehandling().toString());
		
		btnPlukFraMellemvaren = new JButton("Pluk fra mellemvaren");
		btnPlukFraMellemvaren.setBounds(53, 119, 208, 23);
		getContentPane().add(btnPlukFraMellemvaren);
		btnPlukFraMellemvaren.addActionListener(buttonActionListener);
	}
	
	private class ButtonActionsListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource() == btnNsteBehandling) {
				Service.getInstance().naesteBehandling(lp.getMellemvare().getBehandling());
				dispose();
			}
			else if(e.getSource() == btnPlukFraMellemvaren){
				PlukMellemvareFrame frame = new PlukMellemvareFrame(lp.getMellemvare().getBehandling());
				frame.setVisible(true);
			}
			else if(e.getSource() == btnLuk) {
				dispose();
			}
		}
		
	}
}